import {
  Constant_Enum_Enum_Coupon_CouponStatus,
  Constant_Enum_Enum_Coupon_PlatformType,
  Constant_Enum_Enum_Coupon_Scope,
  Constant_Enum_Enum_Coupon_TimeLimitType,
  Constant_Enum_Enum_Coupon_Type,
  Constant_Enum_Enum_Coupon_UseStatus,
  Constant_Enum_Name_Coupon_CouponStatus,
  Constant_Enum_Name_Coupon_PlatformType,
  Constant_Enum_Name_Coupon_Scope,
  Constant_Enum_Name_Coupon_TimeLimitType,
  Constant_Enum_Name_Coupon_Type,
  Constant_Enum_Name_Coupon_UseStatus,
  IConstant_Enum_Type_Coupon_CouponStatus,
  IConstant_Enum_Type_Coupon_PlatformType,
  IConstant_Enum_Type_Coupon_Scope,
  IConstant_Enum_Type_Coupon_TimeLimitType,
  IConstant_Enum_Type_Coupon_Type,
  IConstant_Enum_Type_Coupon_UseStatus,
} from '@/common/constants/enum';
import { ApiProperty } from '@nestjs/swagger';
import { Column, Entity, JoinTable, ManyToMany, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { CouponSort } from '../../couponSort/assets/couponSort.entity';
import { ExCode } from '../../exCode/assets/exCode.entity';
import { CouponUserClient } from '../../couponUserClient/assets/couponUserClient.entity';
import { CouponProduct } from '../../couponProduct/assets/couponProduct.entity';

@Entity()
export class Coupon {
  @PrimaryGeneratedColumn()
  id: number;

  @ManyToMany(() => CouponSort)
  @JoinTable({ name: 'coupon_couponsort' })
  @ApiProperty({ description: '优惠券分类', type: () => CouponSort })
  couponSorts: CouponSort[];

  @Column()
  @ApiProperty({ description: '优惠券名称' })
  couponName: string;

  @Column({ nullable: true })
  @ApiProperty({ description: '优惠券备注' })
  couponRemark?: string;

  @Column()
  @ApiProperty({
    description: '优惠券类型' + Constant_Enum_Name_Coupon_Type,
    enum: Constant_Enum_Enum_Coupon_Type,
  })
  couponType: IConstant_Enum_Type_Coupon_Type;

  @Column({ nullable: true })
  @ApiProperty({ description: '满减金额(元)' })
  reduceMoney?: number;

  @Column({ nullable: true })
  @ApiProperty({ description: '满多少金额' })
  reducePrice?: number;

  @Column({ nullable: true, type: 'float' })
  @ApiProperty({ example: 9.5, type: 'float', description: '折扣（例如:输入9为9折,输入9.5为9.5折）' })
  discount?: number;

  @Column()
  @ApiProperty({
    description: '针对人群' + Constant_Enum_Name_Coupon_Scope,
    enum: Constant_Enum_Enum_Coupon_Scope,
  })
  couponScope: IConstant_Enum_Type_Coupon_Scope;

  @Column()
  @ApiProperty({
    description: '使用时间限制类型' + Constant_Enum_Name_Coupon_TimeLimitType,
    enum: Constant_Enum_Enum_Coupon_TimeLimitType,
  })
  timeLimitType: IConstant_Enum_Type_Coupon_TimeLimitType;

  @Column({ nullable: true, type: 'bigint' })
  @ApiProperty({ description: '固定时间开始范围', type: 'bigint' })
  fixedTimeStart?: number;

  @Column({ nullable: true, type: 'bigint' })
  @ApiProperty({ description: '固定时间结束范围', type: 'bigint' })
  fixedTimeEnd?: number;

  @Column({ nullable: true })
  @ApiProperty({ description: '领取后有效天数' })
  validDays?: number;

  @Column({ nullable: true })
  @ApiProperty({ description: '兑换码' })
  exchangeCode?: string;

  @Column({ nullable: true })
  @ApiProperty({
    description: '商品类型' + Constant_Enum_Name_Coupon_PlatformType,
    enum: Constant_Enum_Enum_Coupon_PlatformType,
  })
  couponPlatformType?: IConstant_Enum_Type_Coupon_PlatformType;

  @ApiProperty({ description: '商品数组', type: () => CouponProduct })
  @OneToMany(() => CouponProduct, (couponProducts) => couponProducts.coupon)
  couponProducts: CouponProduct[];

  @Column()
  @ApiProperty({
    description: '状态' + Constant_Enum_Name_Coupon_CouponStatus,
    enum: Constant_Enum_Enum_Coupon_CouponStatus,
  })
  couponStatus: IConstant_Enum_Type_Coupon_CouponStatus;

  @Column()
  @ApiProperty({
    description: '停用状态' + Constant_Enum_Name_Coupon_UseStatus,
    enum: Constant_Enum_Enum_Coupon_UseStatus,
  })
  useStatus: IConstant_Enum_Type_Coupon_UseStatus;

  @ApiProperty({ description: '单次兑换码', type: () => ExCode })
  @OneToMany(() => ExCode, (exCode) => exCode.coupon)
  exCode: ExCode[];

  @ApiProperty({ description: '优惠券领取情况', type: () => CouponUserClient })
  @OneToMany(() => CouponUserClient, (couponUserClient) => couponUserClient.coupon)
  couponUserClient: CouponUserClient[];
}
